package de.firefligher.network.ice.messenger.server;

public class EventSendMessage extends EventHandler {
	private EventSender sender;
	private String message;
	
	public EventSendMessage(EventSender par1EventSender, String[] par2String) {
		super(par1EventSender, par2String);
		sender = par1EventSender;
		
		if(par2String.length > 0) {
			message = par2String[0];
		} else {
			message = null;
		}
	}

	@Override
	public void run() {
		if(message == null) {
			System.err.println("Coudn't send message because message isn't existing!");
			return;
		}
		
		if(sender instanceof ChatServer) {
			ChatServer server = (ChatServer) sender;
			server.sendMessageToAll(message);
		} else if(sender instanceof Connection) {
			ChatClient client = (ChatClient) sender;
			client.getServer().sendMessageToAll(message);
			client.getServer().sendMessage("[]: " + message);
		}
	}
}
